VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsHSSV"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private m_sMaSV As String
Private m_sMaLop As String
Private m_sMaDT As String
Private m_sHoDem As String
Private m_sTenSV As String
Private m_dtNSinh As Date
Private m_bGioiTinh As Boolean
Private m_sDToc As String
Private m_sHoKhauTT As String
Private m_sTenCha As String
Private m_sTenMe As String
Private m_sGhichu As String

Public Property Get masv() As String
    masv = m_sMaSV
End Property

Public Property Let masv(ByVal sMaSV As String)
    m_sMaSV = sMaSV
End Property

Public Property Get malop() As String
    malop = m_sMaLop
End Property

Public Property Let malop(ByVal sMaLop As String)
    m_sMaLop = sMaLop
End Property

Public Property Get madt() As String
    madt = m_sMaDT
End Property

Public Property Let madt(ByVal sMaDT As String)
    m_sMaDT = sMaDT
End Property

Public Property Get HoDem() As String
    HoDem = m_sHoDem
End Property

Public Property Let HoDem(ByVal sHoDem As String)
    m_sHoDem = sHoDem
End Property

Public Property Get tensv() As String
    tensv = m_sTenSV
End Property

Public Property Let tensv(ByVal sTenSV As String)
    m_sTenSV = sTenSV
End Property

Public Property Get NSinh() As Date
    NSinh = m_dtNSinh
End Property

Public Property Let NSinh(ByVal dtNSinh As Date)
    m_dtNSinh = dtNSinh
End Property

Public Property Get GioiTinh() As Boolean
    GioiTinh = m_bGioiTinh
End Property

Public Property Let GioiTinh(ByVal bGioiTinh As Boolean)
    m_bGioiTinh = bGioiTinh
End Property

Public Property Get DToc() As String
    DToc = m_sDToc
End Property

Public Property Let DToc(ByVal sDToc As String)
    m_sDToc = sDToc
End Property

Public Property Get HoKhauTT() As String
    HoKhauTT = m_sHoKhauTT
End Property

Public Property Let HoKhauTT(ByVal sHoKhauTT As String)
    m_sHoKhauTT = sHoKhauTT
End Property

Public Property Get TenCha() As String
    TenCha = m_sTenCha
End Property

Public Property Let TenCha(ByVal sTenCha As String)
    m_sTenCha = sTenCha
End Property

Public Property Get TenMe() As String
    TenMe = m_sTenMe
End Property

Public Property Let TenMe(ByVal sTenMe As String)
    m_sTenMe = sTenMe
End Property

Public Property Get Ghichu() As String
    Ghichu = m_sGhichu
End Property

Public Property Let Ghichu(ByVal sGhichu As String)
    m_sGhichu = sGhichu
End Property

'---------------------------------------------------------------------------------------
' Procedure : InDanhSach
' Date      : 30/10/2011
' Purpose   : in danh sach sv theo lop nganh
'---------------------------------------------------------------------------------------
Public Function InDanhSach(ByVal malop As String, ByVal manganh As String) As ADODB.Recordset
    Dim sql As String
   On Error GoTo InDanhSach_Error

    sql = "SELECT MaSV, HoDem + ' ' + TenSV AS HoTenSV, NSinh, TenLop, Khoa, TenNganh FROM HSSV sv, LOP l, Nganh ng " & _
                                         "WHERE sv.MaLop = " & IIf(malop <> "", "'" & malop & "'", "sv.MaLop") & " AND " & _
                                               "ng.MaNganh = " & IIf(manganh <> "", "'" & manganh & "'", "ng.MaNganh") & " AND " & _
                                               "sv.MaLop = l.MaLop AND l.MaNganh = ng.MaNganh"
    Call OpenConnection
    ' Create a Recordset by executing an SQL statement.
    Set InDanhSach = g_ObjADOConn.Execute(sql)

   On Error GoTo 0
   Exit Function
InDanhSach_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure InDanhSach of Class Module clsHSSV"
End Function

'---------------------------------------------------------------------------------------
' Procedure : InDanhSachDoiTuong
' Date      : 30/10/2011
' Purpose   : in danh sach sv theo loai doi tuong
'---------------------------------------------------------------------------------------
Public Function InDanhSachDoiTuong(ByVal madt As String) As ADODB.Recordset
    Dim sql As String
   On Error GoTo InDanhSachDoiTuong_Error

    sql = "SELECT MaSV, HoDem + ' ' + TenSV AS HoTenSV, NSinh, TenLop, Khoa, TenNganh FROM HSSV sv, LOP l, Nganh ng " & _
                                         "WHERE MaDT = " & IIf(madt <> "", "'" & madt & "'", "MaDT") & " AND " & _
                                               "sv.MaLop = l.MaLop AND l.MaNganh = ng.MaNganh"
    Call OpenConnection
    ' Create a Recordset by executing an SQL statement.
    Set InDanhSachDoiTuong = g_ObjADOConn.Execute(sql)

   On Error GoTo 0
   Exit Function
InDanhSachDoiTuong_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure InDanhSachDoiTuong of Class Module clsHSSV"
End Function


'---------------------------------------------------------------------------------------
' Procedure : TimKiemSV
' Date      : 30/10/2011
' Purpose   : Tim kiem sv
'---------------------------------------------------------------------------------------
Public Function TimKiem(ByVal masv As String, ByVal tensv As String, ByVal malop As String, ByVal madt As String) As ADODB.Recordset
   On Error GoTo TimKiemSV_Error
    Dim sql As String
    
    sql = "SELECT sv.*, TenLop, Khoa, TenNganh FROM HSSV sv, LOP l, Nganh ng " & _
                                         "WHERE MaSV = " & IIf(masv <> "", "'" & masv & "'", "MaSV") & " AND " & _
                                               "TenSV = " & IIf(tensv <> "", "'" & tensv & "'", "TenSV") & " AND " & _
                                               "sv.MaLop = " & IIf(malop <> "", "'" & malop & "'", "sv.MaLop") & " AND " & _
                                               "MaDT = " & IIf(madt <> "", "'" & madt & "'", "MaDT") & " AND " & _
                                               "sv.MaLop = l.MaLop AND l.MaNganh = ng.MaNganh"
    Call OpenConnection
    ' Create a Recordset by executing an SQL statement.
    Set TimKiem = g_ObjADOConn.Execute(sql)

   On Error GoTo 0
   Exit Function
TimKiemSV_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure TimKiemSV of Class Module clsHSSV"
End Function

'---------------------------------------------------------------------------------------
' Procedure : SelectAll
' Date      : 27/10/2011
' Purpose   : Load danh sach tat ca record cua table co trong file du lieu
'---------------------------------------------------------------------------------------
Public Function SelectAll() As ADODB.Recordset
   On Error GoTo SelectAll_Error

    Call OpenConnection
    ' Create a Recordset by executing an SQL statement.
    Set SelectAll = g_ObjADOConn.Execute("SELECT sv.*, TenLop, TenDT FROM Lop l, HSSV sv, DiemDoiTuong ddt WHERE l.MaLop = sv.MaLop AND sv.MaDT = ddt.MaDT")

   On Error GoTo 0
   Exit Function
SelectAll_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure SelectAll of Class Module clsHSSV"
End Function

'---------------------------------------------------------------------------------------
' Procedure : SelectByID
' Date      : 27/10/2011
' Purpose   : Lay record cua table ung voi ma Lop truyen vao
'---------------------------------------------------------------------------------------
Public Function SelectByID(ByVal ID As String) As ADODB.Recordset
   On Error GoTo SelectByID_Error

    Call OpenConnection
    ' Create a Recordset by executing an SQL statement.
    Set SelectByID = g_ObjADOConn.Execute("SELECT sv.*, TenLop, TenDT FROM Lop l, HSSV sv, DiemDoiTuong ddt WHERE l.MaLop = sv.MaLop AND sv.MaDT = ddt.MaDT AND MaSV = '" & ID & "'")

   On Error GoTo 0
   Exit Function
SelectByID_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure SelectByID of Class Module clsHSSV"
End Function

'---------------------------------------------------------------------------------------
' Procedure : Insert
' Date      : 27/10/2011
' Purpose   : Them 1 record moi vao table trong file du lieu
'---------------------------------------------------------------------------------------
Public Function Insert(ByVal ObjHSSV As clsHSSV) As Boolean
    
   On Error GoTo Insert_Error

    Call OpenConnection
    g_ObjADOConn.Execute ("INSERT INTO HSSV(MaSV, MaLop, MaDT, HoDem, TenSV, NSinh, GioiTinh, DToc, HoKhauTT, TenCha, TenMe, GhiChu) " & _
                          "VALUES('" & ObjHSSV.masv & "', '" & ObjHSSV.malop & "', '" & ObjHSSV.madt & "', '" & ObjHSSV.HoDem & "', '" & ObjHSSV.tensv & "', '" & ObjHSSV.NSinh & "', " & ObjHSSV.GioiTinh & ", '" & ObjHSSV.DToc & "', '" & ObjHSSV.HoKhauTT & "', '" & ObjHSSV.TenCha & "', '" & ObjHSSV.TenMe & "', '" & ObjHSSV.Ghichu & "')")
    Call CloseConnection
    Insert = True
    
   On Error GoTo 0
   Exit Function
Insert_Error:
    Insert = False
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Insert of Class Module clsHSSV"
End Function

'---------------------------------------------------------------------------------------
' Procedure : Delete
' Date      : 27/10/2011
' Purpose   : Xoa 1 record cua table trong file du lieu
'---------------------------------------------------------------------------------------
Public Function Delete(ByVal ID As String) As Boolean
   On Error GoTo Delete_Error

    Call OpenConnection
    g_ObjADOConn.Execute ("DELETE FROM HSSV WHERE MaSV='" & ID & "'")
    Call CloseConnection
    Delete = True
    
   On Error GoTo 0
   Exit Function
Delete_Error:
    Delete = False
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Delete of Class Module clsHSSV"
End Function

'---------------------------------------------------------------------------------------
' Procedure : Update
' Date      : 27/10/2011
' Purpose   : Update record cua table dua tren ID truyen vao
'---------------------------------------------------------------------------------------
Public Function Update(ByVal ObjHSSV As clsHSSV) As Boolean
   On Error GoTo Update_Error

    Call OpenConnection
    g_ObjADOConn.Execute ("UPDATE HSSV " & _
                          "SET MaLop = '" & ObjHSSV.malop & "', " & _
                              "MaDT = '" & ObjHSSV.madt & "', " & _
                              "HoDem = '" & ObjHSSV.HoDem & "', " & _
                              "TenSV = '" & ObjHSSV.tensv & "', " & _
                              "NSinh = '" & ObjHSSV.NSinh & "', " & _
                              "GioiTinh = " & ObjHSSV.GioiTinh & ", " & _
                              "DToc = '" & ObjHSSV.DToc & "', " & _
                              "HoKhauTT = '" & ObjHSSV.HoKhauTT & "', " & _
                              "TenCha = '" & ObjHSSV.TenCha & "', " & _
                              "TenMe = '" & ObjHSSV.TenMe & "', " & _
                              "GhiChu = '" & ObjHSSV.Ghichu & "' " & _
                          "WHERE MaSV = '" & ObjHSSV.masv & "'")
    Call CloseConnection
    Update = True

   On Error GoTo 0
   Exit Function
Update_Error:
    Update = False
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Update of Class Module clsHSSV"
End Function




